﻿using System;
using System.Collections.Generic;

using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.Security;

public partial class Login : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {

    }
    protected void btnLogin_Click(object sender, EventArgs e)
    {
        IList<User> list = new List<User>();
        User user = new User("admin", "admin");
        list.Add(user);
        user = new User("manager", "manager");
        list.Add(user);

        foreach(User u1 in list)
        {
           
            if (txtUsername.Text.Equals(u1.Username) && txtPassword.Text.Equals(u1.Password))
            {
                Session["user"] = txtUsername.Text;
                Profile.Name = txtUsername.Text;
                FormsAuthentication.SetAuthCookie(txtUsername.Text, true);
                if(FormsAuthentication.GetRedirectUrl(txtUsername.Text,true).EndsWith("default.aspx"))
                {
                    HttpContext.Current.Response.Redirect("Default.aspx");
                }
                else
                    Response.Redirect(FormsAuthentication.GetRedirectUrl(txtUsername.Text,true));
            }
            
        }
        
    }
}